package com.yxhl.zoume.core.car.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.yxhl.protobuf.OrderBizType;
import com.yxhl.zoume.R;
import com.yxhl.zoume.common.ui.activity.base.BaseActivityWithToolBar;
import com.yxhl.zoume.core.car.fragment.CarPricingRulesFragment;
import com.yxhl.zoume.di.component.base.HasComponent;
import com.yxhl.zoume.di.component.car.DaggerExpressCarComponent;
import com.yxhl.zoume.di.component.car.ExpressCarComponent;
import com.yxhl.zoume.di.module.ActivityModule;

/**
 * Author：zhongshan   
 * Date：2016/12/15 16:47      
 * Description：计价规则
 */
public class CarPricingRulesActivity extends BaseActivityWithToolBar implements HasComponent<ExpressCarComponent>{

    private static final String INTENT_KEY_VEHICLE_TYPE = "intent_key_vehicle_type";
    private static final String INTENT_KEY_BIZ_TYPE = "intent_key_biz_type";
    private static final String INTENT_KEY_PART_TIME = "intent_key_part_time";


    private String vehicleType;
    private OrderBizType bizType;
    private int partTime;
    private ExpressCarComponent component;

    public static Intent getCallingIntent(Context context, OrderBizType bizType, String vehicleType, int partTime) {
        Intent callingIntent = new Intent(context, CarPricingRulesActivity.class);
        callingIntent.putExtra(INTENT_KEY_VEHICLE_TYPE, vehicleType);
        callingIntent.putExtra(INTENT_KEY_BIZ_TYPE, bizType);
        callingIntent.putExtra(INTENT_KEY_PART_TIME, partTime);
        return callingIntent;
    }

    @Override
    protected void onHeaderLeftClick(View view) {
        finish();
    }

    @Override
    protected void onHeaderRightClick(View view) {

    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_car_pricing_rules;
    }

    @Override
    protected void initializeInjector() {
        component = DaggerExpressCarComponent.builder()
                .appComponent(getAppComponent())
                .activityModule(new ActivityModule(this))
                .build();
    }

    @Override
    public ExpressCarComponent getComponent() {
        return component;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initParams();
        addFragment(R.id.car_pricing_rules_activity_content, CarPricingRulesFragment.newInstance(bizType, vehicleType, partTime), "");
    }

    private void initParams() {
        Intent intent = getIntent();
        if (intent != null) {
            vehicleType = intent.getStringExtra(INTENT_KEY_VEHICLE_TYPE);
            bizType = (OrderBizType) intent.getSerializableExtra(INTENT_KEY_BIZ_TYPE);
            partTime = intent.getIntExtra(INTENT_KEY_PART_TIME, 0);
        }
    }
}
